package com.dhl.fin.api.domain;

import com.dhl.fin.api.common.domain.BasicDomain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.List;

/**
 * Created by CuiJianbo on 2020.02.16.
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "t_role")
public class Role extends BasicDomain {

    @Column(columnDefinition = "varchar(50)")
    private String name;

    @Column(columnDefinition = "varchar(50)")
    private String code;

    public Role() {

    }

    public Role(String name, String code) {
        this.name = name;
        this.code = code;
    }

    /**
     * 关联tree树, 用于存放已选择的菜单权限
     */
    @ManyToMany
    @JoinTable(name = "t_role_tree",
            joinColumns = {@JoinColumn(name = "role_id")},
            inverseJoinColumns = {@JoinColumn(name = "tree_id")})
    private List<Tree> trees;

    /**
     * 关联tree树, 用于存放已选择的数据权限
     */
    @ManyToMany
    @JoinTable(name = "t_role_dataper_tree",
            joinColumns = {@JoinColumn(name = "role_id")},
            inverseJoinColumns = {@JoinColumn(name = "tree_id")})
    private List<Tree> dataPerTrees;


    @ManyToMany
    @JoinTable(name = "t_account_role",
            joinColumns = {@JoinColumn(name = "role_id")},
            inverseJoinColumns = {@JoinColumn(name = "account_id")})
    private List<Account> accounts;

    @ManyToOne
    @JoinColumn(name = "project_id")
    private Project project;

    @Transient
    private List<Long> actionTreeIds;


    @Transient
    private List<Long> dataPerTreeIds;


}
